More problems
[andmenj-acm.git] / 10235 - Simply Emirp / 10235.cpp
blob9472265097c8a605b504e56f2aa258c595aa819d
1 #include <stdlib.h>
2 #include <iostream>
3 #include <math.h>
5 using namespace std;
7 bool esPrimo(const int &n){
8 if (n % 2 == 0)
9 return false;
10 else{
11 int raiz = (int)ceil(sqrt(n)) + 1;
12 for (int i=3; i<raiz; i += 2)
13 if (n % i == 0)
14 return false;
15 return true;
19 int voltear(int n){
20 int r=0;
21 while (n > 0){
22 r = r * 10 + n % 10;
23 n /= 10;
25 return r;
28 int main()
30 int n;
31 while (cin >> n){
32 if (!esPrimo(n))
33 cout << n << " is not prime.\n";
34 else{
35 int inverso = voltear(n);
36 if (inverso != n && esPrimo(inverso))
37 cout << n << " is emirp.\n";
39 else
40 cout << n << " is prime.\n";
43 return 0;